// pages/friends/newFriend/newFriend.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getNewFried()
  },
  //增加朋友
  updataFriend(e){
    let index = e.currentTarget.dataset.index
    let that = this;
    wx.cloud.database().collection('chat_record').doc(this.data.userList[index]._id).update({
      data:{
        friend_status:1
      }
    }).then(res=>{
      if(res.stats.updated ==1) {
        wx.navigateBack({
          delta:0,
          success:res=>{
            wx.showToast({
              title: '成功！',
            })
          }
        })
      }
    })
  },
  //获取申请
getNewFried(){
  let _id = wx.getStorageSync('istokenid')
  wx.cloud.database().collection('chat_record').where({
  userB_id:_id,
  friend_status:0
  }).get().then(res=>{
    console.log(res);
    this.setData({
      userList:res.data
    })
  })
},
})